<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
<head>

<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/icon.css">
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/locale/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){
	
	 $('#dg').datagrid({
         url:"<%=path%>/userAction/getNewsData",
         //开启分页
         pagination : "true",
         //设置分页工具栏位置
         pagePosition : "bottom",
         //设置分页间隔
         pageList : [ 4, 8, 16 ],
         toolbar : "#search",
         pageSize : 4,
         width : 780,
         //是否从服务器对数据进行排序
         //定义顶部工具栏的DataGrid面板
         //定义网格的标题
         toolbar : "#search",
         title : "邮件中心",
         columns : [ [
         //定义列，这里有三列，每一列的都是一个对象，title为列标题，field为字段的名称
         {
             title : "",
             field : "ck",
             checkbox : true
         }, {
             title : "状态",
             field : "icon",
            	 width : 150,
     			align : "center",
     			formatter:showImg

         }, {
             title : "发件人",
             field : "sendUserName",
         	width : 150,
			align : "center",
          
             
         }, {
             title : "标题",
             field : "title",
         	width : 150,
			align : "center",
          
             
         }, {
             title : "时间",
             field : "sendTime",
         	width : 150,
			align : "center",
          
             
         },{
				title:"操作",
				field:"sid",
				width : 150,
				align : "center",
				  formatter : function(value, row, index) {
					  return '<a href="#" onclick="lookEmail('+row["id"]+')"">查看内容</a>  ';  
	                }
			}] ]

     });
	 
	 
	 
	 
	
})

		//图片展示  
		function showImg(value, row, index){  
		        return "<img style='width:24px;height:24px;' border='1' src='<%=path%>/"+value+"'/>";  
		}  

		
		//查看邮件内容
		function lookEmail(emailId){
			var URL="<%=path%>/userAction/lookEmailView?emailId="+emailId;
			
			var iWidth = 1000;
			var iHeight = 600;
			var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
			var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
			var win = window.open(URL, "弹出窗口", "width=" + iWidth + ", height=" + iHeight + ",top=" + iTop + ",left=" + iLeft + ",toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no,alwaysRaised=yes,depended=yes");
		}
				
	
		//批量删除邮件
		function del(){
			var selectionArr =  $('#dg').datagrid('getSelections');
			var ids=[];
			for(var i=0;i<selectionArr.length;i++){
				ids.push(selectionArr[i].id);
				
			};
			
			 $.ajax({
		            //几个参数需要注意一下
		                type: "POST",//方法类型
		                dataType: "json",//预期服务器返回的数据类型
		                data:{'idarr':ids},
		                url: "<%=path%>/userAction/emailDel?idarr="+ids,
		                success: function (result) {
		                	if(result.msg!=""){
			                	$.messager.confirm('确认',result.msg,function(r){    
			                		$('#dg').datagrid('reload');
			                	});  
			                	
		                	}
		                	


		                },
		                error : function() {
		                    alert("系统异常！");
		                }
		            });
			
		}

</script>



<body class="easyui-layout" >   

<div style="margin-left: 250px;">
    <table id="dg" ></table>
   </div>
   
   <div id="search" style="padding: 3px">
			<a href="#" class="easyui-linkbutton" style="margin-left: 75px;" data-options="iconCls:'icon-no'" plain="true" onclick="del();">删除</a>
	</div>
   
</body>  

</html>